package com.ipt.frm.pw;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ipartek.fila2.bean.Alumno;
import com.ipartek.fila2.factoria.DAOFactory;
import com.ipartek.fila2.interfaces.InterfaceAlumnoDAO;
import com.ipartek.fila2.interfaces.InterfaceTiradaDAO;


/**
 * Servlet implementation class servletranking
 */
public class servletRanking extends ServletMaestro {
	private static final long serialVersionUID = 1L;
	
	private static  DAOFactory fMySQL;
	private static  InterfaceAlumnoDAO aDao;
    
	private static final String TABLE_ALUMNO = "alumno";
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public servletRanking() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		processRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		processRequest(request, response);
	}
	
	/**
	 * metodo que enrutador el resultado al jsp encargado de mostrar la lista de ranking
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
	
		
		fMySQL = DAOFactory.getDAOFactory(DAOFactory.MYSQL);

		aDao = fMySQL.getInterfaceAlumnoDAO();

		
		ArrayList<Alumno> listaAlumnos;
		
		try {
			listaAlumnos = aDao.getAlumnosActivos(TABLE_ALUMNO);
			request.setAttribute("ListaAlumnos", listaAlumnos);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		request.setAttribute("tittle", "Ranking de tiradas");
		RequestDispatcher dispacher = this.getServletContext().getRequestDispatcher("/raking.jsp");
		dispacher.forward(request, response);
		
	}

}
